﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO_DTO_WS.DTO;
using DAO_DTO_WS.DAO;

namespace LayoutTemplate
{
    public partial class LichSuMuaHang : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int maThanhVien;
            List<DonHangDTO> dsDonHang = new List<DonHangDTO>();
            try
            {
                maThanhVien = int.Parse(Session["ID"].ToString());
            }
            catch
            {
                Response.Redirect("TrangChu.aspx");
                return;
            }
            dsDonHang = DonHangDAO.layDonHangTheoMaThanhVien(maThanhVien);
            List<LichSuMuaHangDTO> dsls = new List<LichSuMuaHangDTO>();
            for (int i = 0; i < dsDonHang.Count; i++)
            {
                if (dsDonHang[i].TinhTrang == 0)
                {
                    LichSuMuaHangDTO ls = new LichSuMuaHangDTO();
                    ls.MaDonHang = dsDonHang[i].MaDonHang;
                    ls.SoLuong = dsDonHang[i].SoLuong;
                    switch (dsDonHang[i].MaLoaiThanhToan)
                    {
                        case 1: ls.TenLoaiThanhToan = "Ngan Luong"; break;
                        case 2: ls.TenLoaiThanhToan = "PayPal"; break;
                    }
                    SanPhamDTO sanpham = new SanPhamDTO();
                    sanpham = SanPhamDAO.laySPTheoMa(dsDonHang[i].MaSanPham);
                    DoanhNghiepDTO doanhnghiep = DoanhNghiepDAO.LayDNTheoMa(sanpham.MaDoanhNghiep);
                    ls.TenSanPham = sanpham.TieuDe;
                    ls.ThanhTien = dsDonHang[i].TongTien;
                    ls.TenDoanhNghiepBan = doanhnghiep.TenDoanhNghiep;
                    dsls.Add(ls);
                }
            }
            GridView1.DataSource = dsls;
            GridView1.DataBind();
        }
    }
}
